home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / ifft2.cc < prev    next >
C/C++ Source or Header  |  1996-11-03  |  3KB  |  126 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #ifdef HAVE_CONFIG_H
  24. #include <config.h>
  25. #endif
  26.  
  27. #include "defun-dld.h"
  28. #include "error.h"
  29. #include "gripes.h"
  30. #include "help.h"
  31. #include "mappers.h"
  32. #include "oct-obj.h"
  33. #include "utils.h"
  34.  
  35. // This function should be merged with Ffft2.
  36.  
  37. DEFUN_DLD (ifft2, args, ,
  38.   "ifft2 (X [, N] [, M])\n\
  39. \n\
  40. two dimensional inverse fast fourier transform of a vector") 
  41. {
  42.   octave_value_list retval;
  43.  
  44.   int nargin = args.length ();
  45.  
  46.   if (nargin < 1 || nargin > 3)
  47.     {
  48.       print_usage ("ifft2");
  49.       return retval;
  50.     }
  51.  
  52.   octave_value arg = args(0);
  53.  
  54.   int n_rows = arg.rows ();
  55.   if (nargin > 1)
  56.     {
  57.       double dval = args(1).double_value ();
  58.       if (xisnan (dval))
  59.     error ("fft2: NaN is invalid as N_ROWS");
  60.       else
  61.     n_rows = NINT (dval);
  62.     }
  63.  
  64.   if (error_state)
  65.     return retval;
  66.  
  67.   int n_cols = arg.columns ();
  68.   if (nargin > 2)
  69.     {
  70.       double dval = args(2).double_value ();
  71.       if (xisnan (dval))
  72.     error ("fft2: NaN is invalid as N_COLS");
  73.       else
  74.     n_cols = NINT (dval);
  75.     }
  76.  
  77.   if (error_state)
  78.     return retval;
  79.  
  80.   if (n_rows < 0 || n_cols < 0)
  81.     {
  82.       error ("ifft2: number of points must be greater than zero");
  83.       return retval;
  84.     }
  85.  
  86.   int arg_is_empty = empty_arg ("ifft2", arg.rows (), arg.columns ());
  87.  
  88.   if (arg_is_empty < 0)
  89.     return retval;
  90.   else if (arg_is_empty || n_rows == 0 || n_cols == 0)
  91.     return Matrix ();
  92.  
  93.   if (arg.is_real_type ())
  94.     {
  95.       Matrix m = arg.matrix_value ();
  96.  
  97.       if (! error_state)
  98.     {
  99.       m.resize (n_rows, n_cols, 0.0);
  100.       retval = m.ifourier2d ();
  101.     }
  102.     }
  103.   else if (arg.is_complex_type ())
  104.     {
  105.       ComplexMatrix m = arg.complex_matrix_value ();
  106.  
  107.       if (! error_state)
  108.     {
  109.       m.resize (n_rows, n_cols, 0.0);
  110.       retval = m.ifourier2d ();
  111.     }
  112.     }
  113.   else
  114.     {
  115.       gripe_wrong_type_arg ("ifft2", arg);
  116.     }
  117.  
  118.   return retval;
  119. }
  120.  
  121. /*
  122. ;;; Local Variables: ***
  123. ;;; mode: C++ ***
  124. ;;; End: ***
  125. */
  126.